// JavaScript Document

var CB = window.CB = function( eleID, index, extNum ){
	this.eleID = eleID;
	this.index = index? index : 1;
	this.extNum = extNum? extNum : 0;
	this.currentClass = 'current';
	this.currentLink = null;
}

CB.prototype.init = function( links ){
	var t = links[this.index-1];
	DOMHelp.cssjs( "add", t, this.currentClass );
	this.currentLink = t;
}

CB.prototype.switchBg = function( t ){
	DOMHelp.cssjs( "remove", this.currentLink, this.currentClass );
	DOMHelp.cssjs( "add", t, this.currentClass );
	this.currentLink = t;
}

CB.prototype.bind = function(){
	var _this = this;
	var con = document.getElementById( this.eleID );
	var cLinks = con.getElementsByTagName( 'a' );
	
	this.init( cLinks );
	for( var i=0; i<cLinks.length-this.extNum; i++ ){
		var aLink = cLinks[i];
		DOMHelp.addEvent(
			aLink,
			'click',
			function(e){
				var t = DOMHelp.getTarget( e );
				_this.switchBg( t );
			},
			false
		);
	}
}


CB.prototype.bindLi = function(){
	var _this = this;
	var con = document.getElementById( this.eleID );
	
	var lis = con.getElementsByTagName( 'li' );
	this.init( lis );
	
	var cLinks = con.getElementsByTagName( 'a' );
	for( var i=0; i<cLinks.length-this.extNum; i++ ){
		var aLink = cLinks[i];
		DOMHelp.addEvent(
			aLink,
			'click',
			function(e){
				var t = DOMHelp.getTarget( e );
				t = t.parentNode;
				_this.switchBg( t );
			},
			false
		);
	}
}